const cloud = require('wx-server-sdk');
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
});

exports.main = async (event, context) => {
  try {
    const db = cloud.database();
    // 使用 where({}) 来指定更新所有记录
    const result = await db.collection('dailymedicine').where({}).update({
      data: {
        eat: '未服用'
      }
    });
    console.log('成功将所有药品状态重置为未服用', result);
    return { success: true };
  } catch (err) {
    console.error('重置药品状态失败:', err);
    return { success: false, message: err.message };
  }
};